#include <QSettings>
#include <QApplication>
#include <QCommandLineParser>

#include "pdfeditortool.h"
#include "pdfdbgheap.h"

int main(int argc, char *argv[])
{
#if defined(PDF4QT_USE_DBG_HEAP)
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

    QApplication::setAttribute(Qt::AA_CompressHighFrequencyEvents, true);
    QApplication application(argc, argv);

    QCoreApplication::setOrganizationName("GeKuang");
    QCoreApplication::setApplicationName("PDF4QT Editor");
    // QCoreApplication::setApplicationVersion(pdf::PDF_LIBRARY_VERSION);
    QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF阅读器"));

    // QCommandLineOption noDrm("no-drm", "Disable DRM settings of documents.");
    // QCommandLineOption lightGui("theme-light", "Use a light theme for the GUI.");
    // QCommandLineOption darkGui("theme-dark", "Use a dark theme for the GUI.");

    // QCommandLineParser parser;
    // parser.setApplicationDescription(QCoreApplication::applicationName());
    // parser.addOption(noDrm);
    // parser.addOption(lightGui);
    // parser.addOption(darkGui);
    // parser.addHelpOption();
    // parser.addVersionOption();
    // parser.addPositionalArgument("file", "The PDF file to open.");
    // parser.process(application);

    // if (parser.isSet(noDrm))
    // {
    //     pdf::PDFSecurityHandler::setNoDRMMode();
    // }

    // pdf::PDFApplicationTranslator translator;
    // translator.loadSettings();
    // translator.installTranslator();

    // bool isLightGui = false;
    // bool isDarkGui = false;
    // const pdfviewer::PDFViewerSettings::ColorScheme colorScheme = pdfviewer::PDFViewerSettings::getColorSchemeStatic();
    // switch (colorScheme)
    // {
    //     case pdfviewer::PDFViewerSettings::AutoScheme:
    //         isLightGui = parser.isSet(lightGui);
    //         isDarkGui = parser.isSet(darkGui);
    //         break;

    //     case pdfviewer::PDFViewerSettings::LightScheme:
    //         isLightGui = true;
    //         break;

    //     case pdfviewer::PDFViewerSettings::DarkScheme:
    //         isDarkGui = true;
    //         break;

    //     default:
    //         Q_ASSERT(false);
    //         break;
    // }

    // pdf::PDFWidgetUtils::setDarkTheme(isLightGui, isDarkGui);

    QIcon appIcon(":/app-icon.svg");
    QApplication::setWindowIcon(appIcon);

    // pdfviewer::PDFEditorMainWindow mainWindow;
    // mainWindow.show();

    PDFEditorTool* editor = PDFEditorTool::getInstance();

    // 打开PDF文件
    // editor->openDocument("example.pdf");

    // 显示窗口
    editor->showMainWindow();


    // QStringList arguments = parser.positionalArguments();
    // if (!arguments.isEmpty())
    // {
    //     mainWindow.getProgramController()->openDocument(arguments.front());
    // }

    return application.exec();
}
